<?php

defined('_SECURITY_TOKEN') or die("caia fora");

class controllerquery //extends AppController
{

	function __construct(  )
	{
		
		$task	=	application::getTask();//( empty($_REQUEST['task'])? '':$_REQUEST['task']);
		
		switch( $task ){
			
			
			case 'query':
				
				
				
				try {	
        						
					//exige autenticacao de usuário
					//application::IsAuthenticationRequired(true);
					
								
					$parameters =	application::getParameters();
								
					$result 	=	$this->query($parameters->query );
					
					$result=array("status"=>1,
									"data"=>application::arrayToJson($result),
									"notification"=>-1);
											
	
					application::executeView( 'default', $result );
				
			    }
			    catch (AppException $e) {
			    	throw new AppException( $e->getMessage() );
			    	
			    }
				
				break;
				
				
			default:
				
				//echo "view não definida.";
				throw new AppException( MSG_23_METODO_NAO_DEFINIDO );
				
				break;
		}
		
	}
	
	
	public function query( $query ){
				
		$result=false;
		
		try{

			$model	=	application::getModel('query');
			
			$result	=	$model->getQuery( $query );
		
		}
	    catch (AppException $e) {
	    	throw new AppException( $e->getMessage() );
	    }
		

		return $result;
		
	}
	
	
	
	
}